package com.lxg.dao;

import com.lxg.pojo.Problem;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.ArrayList;

@Mapper
public interface ProblemDao {

    /**
     * 查询全部的问题
     * @return
     */
    @Select("select * from problem")
    public ArrayList<Problem> getAllProblem();

    /**
     * 查询未解决的问题
     * @return
     */
    @Select("select * from problem where status=0")
    public ArrayList<Problem> getAllUnsolved();

    /**
     * 查询已经解决的问题
     * @return
     */
    @Select("select * from problem where status=1")
    public ArrayList<Problem> getAllSolved();

    /**
     * 根据pid查询问题
     * @param pid
     * @return
     */
    @Select("select * from problem where pid=#{pid}")
    public Problem getProblemByPid(Integer pid);

    /**
     * 增加一个问题
     * @param uid
     * @param name
     * @param page
     * @param body
     * @param phone
     */
    @Insert("insert into problem (uid,name,page,body,phone) values " +
            "(#{uid},#{name},#{page},#{body},#{phone})")
    public void addProblem(Integer uid,String name,String page,
                           String body,String phone);

    /**
     * 修改问题的状态，改为已解决
     * @param pid
     */
    @Update("update problem set status=1 where pid=#{pid}")
    public void updateProblem(Integer pid);


    @Select("select * from problem where uid=#{uid}")
    ArrayList<Problem> getProblemByUid(Integer uid);

    @Select("select * from problem where  name like CONCAT('%',#{name},'%')")
    ArrayList<Problem> getProblemByLikeName(String name);

    @Select("select * from problem where  body like CONCAT('%',#{body},'%')")
    ArrayList<Problem> getProblemByLikeBody(String body);
}
